﻿<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title - @(Settings.Current.General.SiteTitle ?? "Snippet Box")</title>
    <link href="@Url.Content("~/assets/styles/main.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/assets/themes/" + Settings.Current.General.Theme + "/" + Settings.Current.General.Theme + ".css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/assets/styles/prettify.css")" rel="stylesheet" type="text/css" />
    <link rel="icon" href="/assets/images/favicon.png" type="image/png" />
    <script src="@Url.Content("~/assets/scripts/lib/jquery-1.6.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/assets/scripts/lib/modernizr-1.7.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/assets/scripts/lib/jquery.placeholder.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/assets/scripts/lib/prettify/prettify.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/assets/scripts/snippetbox.js")" type="text/javascript"></script>
    @if (Settings.Current.Advanced.DebugMode) {
    <script>
        // http://w3c-test.org/webperf/specs/NavigationTiming/
        (function (window) {

            // Skip unsupported browsers
            if (!window.performance || !window.performance.timing) {
                return;
            }

            // Output
            function perf() {
                var timing = window.performance.timing, navigation = window.performance.navigation;

                // Separator
                console.info("---Performance Statistics---");

                // Show duration of each important segment
                [
                // Full length of page load, includes redirects and onload events
		['Page Load', timing.navigationStart, timing.loadEventEnd],

                // Resource loading (DNS lookups, TCP connections, resource fetching)
		['Page Resources', timing.fetchStart, timing.responseEnd],

                // Time spent waiting for dom ready events to finish
		['DOM Ready Event', timing.domContentLoadedEventStart, timing.domContentLoadedEventEnd],

                // Time spent waiting for the onload event to finish
		['On Load', timing.loadEventStart, timing.loadEventEnd],

                // Time spent in redirects
		['Redirects', timing.redirectStart, timing.redirectEnd],

                // Time spent doing DNS lookups
		['DNS Lookups', timing.domainLookupStart, timing.domainLookupEnd],

                // Time spent in TCP connections
		['TCP Connections', timing.connectStart, timing.connectEnd],

                // Time spent getting page resources
		['Resources', timing.requestStart, timing.responseEnd],

                // Time spent from the first byte downlaoded, to the last byte
		['Resource Content', timing.responseStart, timing.responseEnd],

                // Time spent rendering the DOM, before the dom ready event
		['DOM Rendering', timing.domLoading, timing.domInteractive],

                // Time spent in previous pages unload event (has to be same origin)
		['Previous Unload', timing.unloadEventStart, timing.unloadEventStart]

	].forEach(function (row) {
	    var name = row[0], length = (row[2] || 0) - (row[1] || 0);

	    if (typeof row[1] == 'number' && typeof row[2] == 'number') {
	        console.info(name + ':', length + 'ms');
	    }
	});

                // Navigation Info
                console.info("-------------");
                console.info('Redirects: ' + navigation.redirectCount);
                console.info('How they got here: ' + (
		navigation.type == navigation.TYPE_NAVIGATE ? 'Link follow or entered in URL bar' :
		navigation.type == navigation.TYPE_RELOAD ? 'Refresh' :
		navigation.type == navigation.TYPE_BACK_FORWARD ? 'Back/Forward Button' :
		navigation.type == navigation.TYPE_RESERVED ? 'Not defined by the browser' :
		'God only knows'
	));


                // For your viewing pleasure
                console.info("-------------");
                console.info('window.performance', window.performance);
            }


            // Delay the perf output until after all load events finish (increase timeout limit if you do image prefetching)
            window.addEventListener('load', function () { setTimeout(perf, 500); }, false);

            // If you would rather call this yourself from the console, comment out the above listener and uncomment the following line
            window.PerformanceStatistics = perf;

        })(this);
    </script>
    }
</head>

<body@(Html.Raw(ViewBag.BodyId != null ? " id=\"" + ViewBag.BodyId + "\"" : ""))>
    <div id="container">
        <header id="siteHeader" class="clearfix">
            <a href="/" id="logo">Snippet Box</a>

            @if (!Request.IsAuthenticated) {
            <div id="loginBox">
                <div id="registerInfoBox" class="infoBox">
                    <p>
                        <b>Why register?</b><br />
                        Save favorite snippets and add new ones.
                    </p> 
                </div>
                
                <form method="post" action="@Url.Action("Login", "User", new { area = "" })">
                    @Html.AntiForgeryToken()
                    @Html.TextBox("Username", null, new { placeholder = "username" })
                    @Html.Password("Password", null, new { placeholder = "password" })
                    <div class="buttons">
                        @if (Settings.Current.Permissions.AllowRegistration) {
                        <a href="@Url.Action("Register", "User")" id="registerButton" class="button">Register</a>
                        }
                        <input type="submit" id="loginButton" name="action" value="Login" />
                    </div>
                </form>
            </div> 
            } else {
            <div id="userMenu">
                @if (User.IsInRole("Member") && Settings.Current.Permissions.AllowMembersToCreateSnippets || User.IsInRole("Editor")) {
                <nav>
                    <p>manage</p>
                    <ul>
                        @if (User.IsInRole("Member")) {
                        <li><a href="@Url.Action("Index", "Snippets", new { area = "manage" })">snippets</a></li>
                        }
                        @if (User.IsInRole("Editor")) {
                        <li><a href="@Url.Action("Index", "Categories", new { area = "manage" })">categories</a></li>
                        }
                        @if (User.IsInRole("SuperAdmin")) {
                        <li><a href="@Url.Action("Index", "Users", new { area = "manage" })">users</a></li>
                        }
                        @if (User.IsInRole("Admin")) {
                        <li><a href="@Url.Action("Index", "Settings", new { area = "manage" })">settings</a></li>
                        }
                    </ul>
                </nav>
                }
                <nav>
                    <p>@User.Identity.Name</p>
                    <ul>
                        <li><a href="/users/@User.Identity.Name">profile</a></li>
                        <li><a href="@Url.Action("Logout", "User", new { area = ""})">logout</a></li>
                    </ul>
                </nav>
            </div>
            }
        </header>
        
        <nav id="categoryMenu">
@Html.RenderCategoryMenu()
        </nav>

        <div id="contentArea">
            <div id="search">
                <form method="get" action="@Url.Action("Index", "Search", new { area = "" })">
                    <input type="text" name="query" value="@Html.AttributeEncode(Request.QueryString["query"])" placeholder="find snippets" required />
                    <input type="submit" value="search" />
                </form>
            </div>

            <div id="content">
                @RenderBody()
            </div>
        </div>
        <footer id="footer">
            Snippet Box 1.0.0 - created by @@<a href="http://twitter.com/#!/codingbug" target="_blank">codingbug</a>
        </footer>
    </div>
</body>
</html>
